package org.dromara.bykt.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.bykt.domain.vo.BYKTCourseVideoVo;
import org.dromara.bykt.domain.bo.BYKTCourseVideoBo;
import org.dromara.bykt.service.IBYKTCourseVideoService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 课程视频
 *
 * @author Hou
 * @date 2025-06-22
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/bykt/video")
public class BYKTCourseVideoController extends BaseController {

    private final IBYKTCourseVideoService courseVideoService;

    /**
     * 查询课程视频列表
     */
    @GetMapping("/list")
    public TableDataInfo<BYKTCourseVideoVo> list(BYKTCourseVideoBo bo, PageQuery pageQuery) {
        return courseVideoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出课程视频列表
     */
    @Log(title = "课程视频", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response) {
//        List<BYKTCourseVideoVo> list = courseVideoService.queryList(bo);
        ExcelUtil.exportExcel(null, "课程视频", BYKTCourseVideoVo.class, response);
    }

    /**
     * 获取课程视频详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<BYKTCourseVideoVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(courseVideoService.queryById(id));
    }

    /**
     * 新增课程视频
     */
    @Log(title = "课程视频", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add(@RequestBody BYKTCourseVideoBo bo) {
        return toAjax(courseVideoService.insertByBo(bo));
    }

    /**
     * 修改课程视频
     */
    @Log(title = "课程视频", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit(@RequestBody BYKTCourseVideoBo bo) {
        return toAjax(courseVideoService.updateByBo(bo));
    }

    /**
     * 删除课程视频
     *
     * @param ids 主键串
     */
    @Log(title = "课程视频", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(courseVideoService.deleteWithValidByIds(List.of(ids), true));
    }
}
